package com.xuyy.exportword.controller;


import com.xuyy.exportword.util.ImageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
public class IndexController {

    @RequestMapping("/")
    public String index(ModelMap map) {
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host", "http://blog.didispace.com");
        // return模板文件的名称，对应src/main/resources/templates/index.html
        return "index";
    }

    /**
     * 保存图片
     */
    @RequestMapping("/saveImage")
    @ResponseBody
    public boolean saveImage(HttpServletRequest request) {
        boolean b = false;
        String barBase64Info = request.getParameter("baseimg");
        try {
            b = ImageUtil.savePictoServer(barBase64Info, "image");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return b;
    }
}